<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>系统登录</title>
  <link rel="stylesheet" href="css/login.css">
  <script type="text/javascript" src="js/jquery.min.js"></script>
  <script src="./layui/layui.js" charset="utf-8"></script>
</head>
<body class="login-bg">

    <div class="login">
        <div class="message">系统登录</div>
        <div id="darkbannerwrap"></div>   
        <form method="post" class="layui-form" >
            <input name="username" placeholder="用户名"  type="text" lay-verify="required" class="layui-input" >
            <hr class="hr15">
            <input name="password" lay-verify="required" placeholder="密码"  type="password" class="layui-input">
            <hr class="hr15">
            <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="button" id="loginbtn">
            <hr class="hr20" >
        </form>
    </div>
    <script>
            layui.use(['form','jquery'], function() {
                $ = layui.jquery;
                var form = layui.form(),
                layer = layui.layer;

                //监听提交
                form.on('submit(login)', function(data) {
                    //alert(1);
                    /*console.log(data);*/
                    // layer.alert(JSON.stringify(data.field), {
                    //   title: '点击确定进入后台'
                    // },function  () {
                    //     location.href = "./index.html";
                    // })
                    // return false;

                });

                // 进行登录操作
                $("#loginbtn").on('click',function (){
                    var username = $("input[name='username']").val();
                    var pwd = $("input[name='password']").val();
                    var captcha = $("input[name='captcha']").val();

                    if (username == '') {
                        layer.msg('用户名不能为空');
                        return ;
                    }
                    if (pwd == '') {
                        layer.msg('密码不能为空');
                        return ;
                    }

                    $.ajax({
                        type:"post",
                        url:"user/login",
                        data:"username="+username+"&pwd="+pwd+"&captcha="+captcha,
                        dataType:'json',
                        success:function (jsonObj){
                            if(jsonObj.code ===0){
                                location.href = "./index.html";
                            }else {
                                layer.msg(jsonObj.msg);
                            }

                        }

                    })

                })

            });

        </script>

    
    <!-- 底部结束 -->
    
</body>
</html>